package com.moss.cloud.auth.biz.events;

import com.moss.cloud.common.core.constant.Constant;
import com.moss.cloud.common.core.constant.MsgTopic;
import com.moss.cloud.common.core.enums.MsgActionEnum;
import com.moss.cloud.common.core.enums.MsgTypeEnum;
import com.moss.cloud.common.core.model.dto.MessageDTO;
import com.moss.cloud.common.core.model.dto.UserLoginDTO;
import com.moss.cloud.common.security.component.MessageEventSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class LoginEvent {
    private final MessageEventSender messageEventSender;

    public LoginEvent(MessageEventSender messageEventSender) {
        this.messageEventSender = messageEventSender;
    }

    /**
     * 用户登录成功发送消息
     * @param dto
     */
    public void sendUserLoginEvent(UserLoginDTO dto){
        if(!dto.getAccountNumber().equals(Constant.DEF_CLIENT)){
            log.info("用户登录授权成功，发送MQ消息通知");
            messageEventSender.sendMessage(MsgTopic.USER_LOGIN_MESSAGE,new MessageDTO(
                    MsgTypeEnum.ONE.name(), MsgActionEnum.ADD.name(),dto));
        }
    }
}
